import 'package:json2dart_safe/json2dart.dart';

import '../../utils/enum.dart';
import '../../utils/extension.dart';
import '../axis_cover.dart';
import '../tag/tags_model.dart';

class VideoDetail extends AxisCover {
  bool? attention;
  bool? canWatch;
  String? checkSum;
  int? commentNum;
  List<String>? coverImg;
  String? createdAt;
  int? fakeFavorites;
  int? fakeLikes;
  int? fakeScoreNum;
  int? fakeShareNum;
  int? fakeWatchNum;
  int? height;
  bool? like;
  String? logo;
  String? nickName;
  String? playPath;
  int? playTime;
  double? price;
  //不能关于原因 1-无次数 2-需要付费 3-需要vip 4-无粉丝团门票
  VideoReasonTypeEnum? reasonType;
  double? score;
  int? size;
  String? subtitle;
  List<TagsModel>? tags;
  String? title;
  int? userId;
  List<String>? verticalImg;
  int? videoId;
  int? videoType;
  String? videoUrl;
  int? width;

  @override
  String get vCover => verticalImg?.firstOrNull ?? '';
  @override
  String get hCover => coverImg?.firstOrNull ?? '';
  String get priceText => price?.toStringAsShort() ?? '';

  Map<String, dynamic> toJson() {
    return <String, dynamic>{}
      ..put('canWatch', canWatch)
      ..put('checkSum', checkSum)
      ..put('commentNum', commentNum)
      ..put('coverImg', coverImg)
      ..put('createdAt', createdAt)
      ..put('fakeFavorites', fakeFavorites)
      ..put('fakeLikes', fakeLikes)
      ..put('fakeShareNum', fakeShareNum)
      ..put('fakeWatchNum', fakeWatchNum)
      ..put('height', height)
      ..put('like', like)
      ..put('attention', attention)
      ..put('playTime', playTime)
      ..put('price', price)
      ..put('reasonType', reasonType)
      ..put('size', size)
      ..put('title', title)
      ..put('verticalImg', verticalImg)
      ..put('videoId', videoId)
      ..put('videoUrl', videoUrl)
      ..put('width', width)
      ..put('playPath', playPath)
      ..put('logo', logo)
      ..put('nickName', nickName)
      ..put('userId', userId);
  }

  VideoDetail.fromJson(Map<String, dynamic> json) {
    canWatch = json.asBool('canWatch');
    checkSum = json.asString('checkSum');
    commentNum = json.asInt('commentNum');
    coverImg = json.asList<String>('coverImg');
    createdAt = json.asString('createdAt');
    fakeFavorites = json.asInt('fakeFavorites');
    fakeLikes = json.asInt('fakeLikes');
    fakeScoreNum = json.asInt('fakeScoreNum');
    fakeShareNum = json.asInt('fakeShareNum');
    fakeWatchNum = json.asInt('fakeWatchNum');
    height = json.asInt('height');
    like = json.asBool('like');
    attention = json.asBool('attention');
    // 'https://live-par-2-abr.livepush.io/vod/bigbuckbunnyclip.mp4';
    playPath = json.asString('playPath');
    playTime = json.asInt('playTime');
    price = json.asDouble('price');
    reasonType = json.asInt('reasonType');
    score = json.asDouble('score');
    size = json.asInt('size');
    subtitle = json.asString('subtitle');
    tags = json.asList<TagsModel>('tags', TagsModel.toBean);
    title = json.asString('title');
    verticalImg = json.asList<String>('verticalImg', null);
    videoId = json.asInt('videoId');
    videoType = json.asInt('videoType');
    videoUrl = json.asString('videoUrl');
    width = json.asInt('width');
    logo = json.asString('logo');
    nickName = json.asString('nickName');
    userId = json.asInt('userId');
  }

  static dynamic toBean(Map json) =>
      VideoDetail.fromJson(Map<String, dynamic>.from(json));
}
